public class Main {
    public static void main(String[] args) {
        System.out.println(new Solution().canJump(new int[]{2,3,1,1,4}));
        System.out.println(new Solution().canJump(new int[]{3,2,1,0,4}));
    }
}

class Solution {
    public boolean canJump(int[] nums) {
        int maxIdx = 0;
        for (int i = 0; i <= maxIdx; i++) {
            maxIdx = Math.max(maxIdx, i + nums[i]);
            if (maxIdx >= nums.length - 1) {
                return true;
            }
        }
        return false;
    }
}